<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/welcome' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>商品管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片区 -->
    <el-card>
      <!-- 顶部搜索区 -->
      <el-row :gutter="20">
        <el-col :span="8">
          <div class="grid-content bg-purple">
            <el-input
              clearable
              v-model="queryInfo.query"
              placeholder="请输入内容"
              class="input-with-select"
            >
              <el-button slot="append" icon="el-icon-search"></el-button>
            </el-input>
          </div>
        </el-col>
        <el-col :span="4">
          <div class="grid-content bg-purple">
            <el-button type="primary">添加商品 </el-button>
          </div>
        </el-col>
      </el-row>
      <!-- 表格区 -->
      <el-table :data="list" style="width: 100%">
        <el-table-column prop="order_number" label="订单编号" width="720">
        </el-table-column>
        <el-table-column prop="order_price" label="订单价格"> </el-table-column>
        <el-table-column prop="order_pay" label="是否付款">
          <template v-slot="{ row }">
            <el-tag type="success" v-if="row.order_pay == 1">已付款</el-tag>
            <el-tag type="danger" v-else>未付款 </el-tag>
          </template>
        </el-table-column>

        <el-table-column prop="is_send" label="是否发货"> </el-table-column>

        <el-table-column prop="create_time" label="下单时间" width="100">
          <template v-slot="{ row }">
            {{ row.create_time | date('yyyy-MM-dd') }}
          </template>
        </el-table-column>

        <el-table-column prop="address" label="操作" width="250">
          <template>
            <!-- {{ row.order_id }} -->
            <el-button type="primary" size="mini" @click="editbtns"
              >修改地址</el-button
            >
            <el-button type="danger" size="mini" @click="querybtn"
              >查询物流</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <!-- 页码区 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[10, 15, 20, 30]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
      <!-- 修改地址对话框 -->
      <el-dialog
        title="修改地址"
        :visible.sync="editbtn"
        width="50%"
        @close="editclose"
      >
        <!-- 修改地址表单 -->
        <el-form
          :model="editForm"
          :rules="editrules"
          ref="editFormref"
          label-width="100px"
          class="demo-ruleForm"
        >
          <el-form-item label="省市" prop="address">
            <el-cascader
              v-model="citydatalist"
              :options="citydata"
              :props="propobj"
              @change="handleChange"
            ></el-cascader>
          </el-form-item>
          <el-form-item label="区县" prop="addressinfo">
            <el-input v-model="editForm.addressinfo"></el-input>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="editbtn = false">取 消</el-button>
          <el-button type="primary" @click="editbtn = false">确 定</el-button>
        </span>
      </el-dialog>
      <!-- 查询物流对话框 -->
      <el-dialog title="物流信息" :visible.sync="querymsg" width="50%">
        <!-- 时间线 -->
        <el-timeline>
          <el-timeline-item
            v-for="(activity, index) in querymsglist"
            :key="index"
            icon="el-icon-more"
            size="large"
            type="primary"
            color="skyblue"
            :timestamp="activity.ftime"
          >
            {{ activity.context }}
          </el-timeline-item>
        </el-timeline>
        <span slot="footer" class="dialog-footer">
          <el-button @click="querymsg = false">取 消</el-button>
          <el-button type="primary" @click="querymsg = false">确 定</el-button>
        </span>
      </el-dialog>
    </el-card>
  </div>
</template>

<script>
import citydata from './citydata'
export default {
  name: '',
  data() {
    return {
      //查询的数据
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 10
      },
      total: 0,
      // 数据列表
      list: [],
      // 修改表单对话框
      editbtn: false,
      //查询物流对话框
      querymsg: false,
      editForm: {
        address: ''
      },
      editrules: {
        address: [
          { required: true, message: '请输入活动名称', trigger: 'blur' }
        ],
        addressinfo: [
          { required: true, message: '请输入活动名称', trigger: 'blur' }
        ]
      },
      citydata,
      // 级联选中数组
      citydatalist: [],
      // prop配置项
      propobj: {
        expandTrigger: 'hover',
        children: 'children',
        label: 'label',
        value: 'value'
      },
      // 物流数据列表
      querymsglist: []
    }
  },
  created() {
    this.getlist()
  },
  // mounted () {},
  computed: {},
  watch: {},
  methods: {
    // 获取数据列表渲染页面用
    async getlist() {
      const { data: res } = await this.$http.get(`orders`, {
        params: this.queryInfo
      })
      // console.log(res.data.goods);
      if (res.meta.status !== 200) {
        return this.$message.error('获取用户列表失败！')
      }
      this.list = res.data.goods
      this.total = res.data.total
    },
    editbtns() {
      this.editbtn = true
    },
    editclose() {
      this.$refs.editFormref.resetFields()
      this.citydatalist = []
    },
    handleChange() {
      console.log(this.citydatalist)
    },
    async querybtn() {
      console.log(111)
      const { data: res } = await this.$http.get('/kuaidi/804909574412544580')
      console.log(res.data)
      this.querymsglist = res.data
      this.querymsg = true
    },
    handleSizeChange(val) {
      this.queryInfo.pagesize = val
      this.getlist()
      console.log(`每页 ${val} 条`)
    },
    handleCurrentChange(val) {
      this.queryInfo.pagenum = val
      this.getlist()

      console.log(`当前页: ${val}`)
    }
  }
}
</script>

<style lang="less" scoped></style>
